package com.mc2.docapp.disabilityassessmenttool.UpperLimb;


import io.realm.RealmObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class C_ulmp_shoulder extends RealmObject {
    private CustDataType flexion= new CustDataType();
    private CustDataType extension= new CustDataType();
    private CustDataType internal_rotation= new CustDataType();
    private CustDataType external_rotation= new CustDataType();
    private CustDataType adduction= new CustDataType();
    private CustDataType abduction= new CustDataType();
    private InnerCalculations inner_calculations = new InnerCalculations();

    public void calc(C_ulmp_shoulder c_ulmp_shoulder) {
        double a = c_ulmp_shoulder.getFlexion().getActual_right();
        double b = c_ulmp_shoulder.getExtension().getActual_right();
        double c = c_ulmp_shoulder.getInternal_rotation().getActual_right();
        double d = c_ulmp_shoulder.getExternal_rotation().getActual_right();
        double e = c_ulmp_shoulder.getAdduction().getActual_right();
        double f = c_ulmp_shoulder.getAbduction().getActual_right();

        double pa = perc(a, c_ulmp_shoulder.getFlexion().getNormal());
        double pb = perc(b, c_ulmp_shoulder.getExtension().getNormal());
        double pc = perc(c, c_ulmp_shoulder.getInternal_rotation().getNormal());
        double pd = perc(d, c_ulmp_shoulder.getExternal_rotation().getNormal());
        double pe = perc(e, c_ulmp_shoulder.getAdduction().getNormal());
        double pf = perc(f, c_ulmp_shoulder.getAbduction().getNormal());

        double x = (pa + pb + pc + pd + pe + pf) / 6.0;

        c_ulmp_shoulder.getFlexion().setPerc_loss_right(pa);
        c_ulmp_shoulder.getExtension().setPerc_loss_right(pb);
        c_ulmp_shoulder.getInternal_rotation().setPerc_loss_right(pc);
        c_ulmp_shoulder.getExternal_rotation().setPerc_loss_right(pd);
        c_ulmp_shoulder.getAdduction().setPerc_loss_right(pe);
        c_ulmp_shoulder.getAbduction().setPerc_loss_right(pf);

        //LEFT CALCULATIONS

        a = c_ulmp_shoulder.getFlexion().getActual_left();
        b = c_ulmp_shoulder.getExtension().getActual_left();
        c = c_ulmp_shoulder.getInternal_rotation().getActual_left();
        d = c_ulmp_shoulder.getExternal_rotation().getActual_left();
        e = c_ulmp_shoulder.getAdduction().getActual_left();
        f = c_ulmp_shoulder.getAbduction().getActual_left();

        pa = perc(a, c_ulmp_shoulder.getFlexion().getNormal());
        pb = perc(b, c_ulmp_shoulder.getExtension().getNormal());
        pc = perc(c, c_ulmp_shoulder.getInternal_rotation().getNormal());
        pd = perc(d, c_ulmp_shoulder.getExternal_rotation().getNormal());
        pe = perc(e, c_ulmp_shoulder.getAdduction().getNormal());
        pf = perc(f, c_ulmp_shoulder.getAbduction().getNormal());


        double y = (pa + pb + pc + pd + pe + pf) / 6.0;

        c_ulmp_shoulder.getFlexion().setPerc_loss_left(pa);
        c_ulmp_shoulder.getExtension().setPerc_loss_left(pb);
        c_ulmp_shoulder.getInternal_rotation().setPerc_loss_left(pc);
        c_ulmp_shoulder.getExternal_rotation().setPerc_loss_left(pd);
        c_ulmp_shoulder.getAdduction().setPerc_loss_left(pe);
        c_ulmp_shoulder.getAbduction().setPerc_loss_left(pf);
        c_ulmp_shoulder.setInner_calculations(new InnerCalculations(
                x,
                y,
                x * 0.3,
                y * 0.3
        ));
    }

    private double perc(double a, double normal) {
        return ((normal - a) * 100d) / (normal + 0d);
    }


}
